package com.googlecode.recycled.data;


import com.googlecode.recycled.lang.Closeable;
import smokesignals.data.QueryHandler;

/**
 * Implementors can access particular data store type for read and write.
 *
 * @param <I> Type of id used by this store.
 */
public interface DataStore<I> extends Closeable {

    /**
     * Saves entity into the data store.
     *
     * @param withId Non-null entity to store (save or update). Entities with null id are transient - therefore they
     *               are created during the store process. Entities with non-null id are already persisted - therefore
     *               they are updated during the store process.
     * @throws com.googlecode.recycled.lang.assertions.NotNullAssertionException
     *          If entity is null.
     */
    void store(WithId<I> withId);

    /**
     * Removes entity from the datastore.
     *
     * @param withId Entity to be removed from the datastore.
     * @throws com.googlecode.recycled.lang.assertions.NotNullAssertionException
     *          If entity is null.
     */
    void delete(WithId<I> withId);

    <R extends WithId<I>> R load(Class<R> clazz, I id);

    <Q, R> Iterable<R> query(Q query, Object... parameters);

    void registerQuerySupport(Class queryType, QueryHandler queryHandler);

}
